﻿using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using DAL;
using Model;
public partial class Admin_UserPayList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!Page.IsPostBack)
        {
            DataLoad();
        }
    }


    private void DataLoad()
    {
        BindUser();
        BindPay();
        BindBll();
    }
    private void BindUser()
    {
        User user = new User();


        user = new UserService().GetUser(int.Parse(Request.QueryString["id"].ToString()));


        username.Text = user.TrueName;
        zhoushen.Text = user.State;
        dianhua.Text = user.Mobile;
        youbian.Text = user.ZipCode;
        dizhilb.Text = user.Address;
        gongsilb.Text = user.Company;
        guojia.Text = user.Country;

        chengshi.Text = user.City;
    }
    private void BindPay()
    {

        string endzhouqi = "";
        string qixian = "";
        string shangqi = "";
        string zhongliang = "";
        string dianfu = "";
        string daigou = "";
        string baozhuang = "";
        string guanshui = "";
        string baoxian = "";
        string qiyta = "";
        string youhui = "";
        string benqi = "";
        sdate.Text = Request.QueryString["year"].ToString() + "/0" + Request.QueryString["yue"].ToString() + "/01";
        if (new UserService().GetUserNow(Request.QueryString["id"].ToString(), Request.QueryString["year"].ToString(), Request.QueryString["yue"].ToString(), ref endzhouqi, ref qixian, ref shangqi, ref zhongliang, ref dianfu, ref daigou, ref baozhuang, ref guanshui, ref baoxian, ref  qiyta, ref youhui, ref benqi))
        {

            DateTime d = new Tools().StringToTime(endzhouqi);
            DateTime n = DateTime.Now;
            if ((d.Year == n.Year) && (d.Month == n.Month))
            {
                edate.Text = n.ToShortDateString();
            }
            else
            {
                edate.Text = endzhouqi;
            }
            shangqijieyu.Text = shangqi;
            zhongliangfei.Text = zhongliang;
            dianfufei.Text = dianfu;
            daigoufei.Text = daigou;

            baozhuangfei.Text = baozhuang;
            guanshuilb.Text = guanshui;
            baoxianfei.Text = baoxian;
            qitafei.Text = qiyta;
            youhuilb.Text = youhui;
            benqijieyu.Text = benqi;
            qixiandate.Text = qixian;


        }
        else
        {
            Tools.OpenWindow(this, "没数据？");
        }
    }

    private void BindBll()
    {
        string year = Request.QueryString["year"].ToString();
        string yue = Request.QueryString["yue"].ToString();
        string beginDate = "";
        string endDate = "";


        beginDate = year + "-" + yue + "-01" + " 00:00:00";



        string mend = "";


        if (yue.Trim() == "12")
        {
            mend = (int.Parse(year) + 1).ToString() + "-01-01 23:59:59";//下1年的1月


        }
        else
        {
            mend = year + "-" + (int.Parse(yue) + 1) + " -01 23:59:59";

        }
        // SysTemError.SystemLog(mend);
        endDate = DateTime.Parse(mend).AddDays(-1).ToString();


        //WayBill mbill = new WayBill();
        //WayBillService mbills = new WayBillService();
        string sql = " userid=" + Request.QueryString["id"].ToString() + "and PayDate >= cast('" + beginDate + "' as datetime)  and  PayDate<= cast('" + endDate + "' as datetime ) ";
        DataTable ntd = new PublicSqlService().GetData("SepTotal,TrackingNo,CreateDate,UPEXState,sep,SepChargedWt,Sender,Receiver,NoOfPiece,ChargedWt,FlightNo,Total,'' as Pay", "Tbl_WayBill", " CreateUserID= " + Request.QueryString["id"].ToString() + "and CreateDate >= cast('" + beginDate + "' as datetime)  and  CreateDate<= cast('" + endDate + "' as datetime ) and StateID<>1 ");
        DataTable dt = new PublicSqlService().GetData("PayType,ReMark,PayAll,PayDate", "Tb_Pay", sql);

        PublicSqlService ps = new PublicSqlService();
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            DataRow dr = ntd.NewRow();
            dr[0] = dt.Rows[i]["PayType"].ToString();
            dr[1] = "  ";
            dr[2] = dt.Rows[i]["PayDate"].ToString();
            dr[3] = "  ";
            dr[4] = "  ";
            dr[5] = "";
            dr[6] = "  ";
            dr[7] = "  ";
            dr[8] = "";
            dr[9] = "";
            dr[10] = "";
            dr[11] = "";
            dr[12] = dt.Rows[i]["PayAll"].ToString();
            ntd.Rows.Add(dr);

        }

        DataView dv = ntd.DefaultView;
        dv.Sort = "CreateDate";



        // mbills.GetAllForUPEX(int.Parse(Request.QueryString["id"].ToString()), 1, 1000, "", "", "", "", "", "", "", "", beginDate, endDate, 1, 0, "", "", "");

        billlist.DataSource = dv;
        billlist.DataBind();
    }
    Tools t = new Tools();
    public int Toint(object v)
    {

        return t.StringToIntDif(v);
    }
    public DataTable getrpro(string tn)
    {
        if (tn.ToString() != "")
        {
            string getword = "SepNo,TrackingNo,SBState,SendBy,CHNReceiver,Pieces,ChargedWt,FlightNo,CreateDate,Logo,Memo1,Total,State";
            return new PublicSqlService().GetData(getword, "Tbl_SepBill", "TrackingNo='" + tn.Trim() + "'");
        }
        else
        {
            return null;
        }
    }


}
//你上了，请测试下系统管理，已经修改完成。如果没什么问题，请电话联系刘总，确认下你们这边没问题。因为